#import "dfhgwhruebvhrheyaveragebid.h"
#define  	boxWidth  35
#define 	DEFAULTFONT(SIZE)  [UIFont systemFontOfSize:SIZE]
#define 	HLLineColor [UIColor grayColor]
@implementation dfhgwhruebvhrheyaveragebid
- (id)initWithFrame:(CGRect)frame
		  WithTitle:(NSString *)title
		 WithButton:(NSArray *)bttonArray {
	self = [super initWithFrame:frame];
	if (self) {
		self.backgroundColor = [UIColor clearColor];
		UIView *viewBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, dhgfywegwygeydwdispositionvisualize, dhgfywegwygeydwchaselocality)];
		viewBG.backgroundColor = [UIColor blackColor];
		viewBG.alpha = 0.4;
		viewBG.userInteractionEnabled = YES;
		UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeFromView)];
		[viewBG addGestureRecognizer:tap];
		[self addSubview:viewBG];
		UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 100, dhgfywegwygeydwdispositionvisualize-60, 148)];
		view.php_center_y = dhgfywegwygeydwchaselocality/2;
		[view.layer setCornerRadius:8];
		[view.layer setMasksToBounds:YES];
		view.backgroundColor = [UIColor whiteColor];
		view.userInteractionEnabled = YES;
		[self addSubview:view];
		_lable_title = [[UILabel alloc]init];
		_lable_title.frame = CGRectMake(10, 19, view.frame.size.width-20, 16);
		_lable_title.text = [NSString stringWithFormat:@"%@",title];
		_lable_title.textAlignment=1;
		_lable_title.font = DEFAULTFONT(15);
		_lable_title.textColor = [UIColor blackColor];
		[view addSubview:_lable_title];
		_TF = [[UITextField alloc]init];
		_TF.frame = CGRectMake(0, 0, 0, 0);
		_TF.delegate = self;
		_TF.keyboardType=UIKeyboardTypeNumberPad;
		[_TF addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
		[view addSubview:_TF];
		CGFloat space=(view.frame.size.width-boxWidth*6-15)/2;
		_view_box=[self setupViewAddView:view];
		_view_box.php_x=space;
		_view_box2=[self setupViewAddView:view];
		_view_box2.php_x=space+(boxWidth+3)*1;
		_view_box3=[self setupViewAddView:view];
		_view_box3.php_x=space+(boxWidth+3)*2;
		_view_box4=[self setupViewAddView:view];
		_view_box4.php_x=space+(boxWidth+3)*3;
		_view_box5=[self setupViewAddView:view];
		_view_box5.php_x=space+(boxWidth+3)*4;
		_view_box6=[self setupViewAddView:view];
		_view_box6.php_x=space+(boxWidth+3)*5;
		_lable_point=[self setupLabelAddView:_view_box];
		_lable_point2=[self setupLabelAddView:_view_box2];
		_lable_point3=[self setupLabelAddView:_view_box3];
		_lable_point4=[self setupLabelAddView:_view_box4];
		_lable_point5=[self setupLabelAddView:_view_box5];
		_lable_point6=[self setupLabelAddView:_view_box6];
		if(bttonArray.count>0) {
			UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_view_box.frame)+15, view.frame.size.width, 0.5)];
			line.backgroundColor = HLLineColor;
			[view addSubview:line];
			for(int i=0;i<bttonArray.count;i++) {
				UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
				btn.frame = CGRectMake(0+(view.frame.size.width/bttonArray.count)*i, CGRectGetMaxY(line.frame), view.frame.size.width/bttonArray.count, view.frame.size.height-CGRectGetMaxY(line.frame));
				[btn setTitleColor:[UIColor darkGrayColor] forState:0];
				btn.backgroundColor = [UIColor clearColor];
				btn.titleLabel.font = DEFAULTFONT(15);
				[btn setTitle:[bttonArray objectAtIndex:i] forState:0];
				[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
				btn.tag = i;
				[view addSubview:btn];
				if(i == bttonArray.count-1) {
					[btn setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
				} else {
					UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake((view.frame.size.width/bttonArray.count)*(i+1), CGRectGetMaxY(line.frame), 0.5, view.frame.size.height-CGRectGetMaxY(line.frame))];
					line1.backgroundColor = HLLineColor;
					[view addSubview:line1];
				}
			}
		}
	}
	return self;
}
-(void)textFieldDidChange:(id) sender {
	UITextField *_field = (UITextField *)sender;
	switch (_field.text.length) {
		case 0:{
			_lable_point.hidden=YES;
			_lable_point2.hidden=YES;
			_lable_point3.hidden=YES;
			_lable_point4.hidden=YES;
			_lable_point5.hidden=YES;
			_lable_point6.hidden=YES;
		}
			break;
		case 1:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=YES;
			_lable_point3.hidden=YES;
			_lable_point4.hidden=YES;
			_lable_point5.hidden=YES;
			_lable_point6.hidden=YES;
		}
			break;
		case 2:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=NO;
			_lable_point3.hidden=YES;
			_lable_point4.hidden=YES;
			_lable_point5.hidden=YES;
			_lable_point6.hidden=YES;
		}
			break;
		case 3:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=NO;
			_lable_point3.hidden=NO;
			_lable_point4.hidden=YES;
			_lable_point5.hidden=YES;
			_lable_point6.hidden=YES;
		}
			break;
		case 4:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=NO;
			_lable_point3.hidden=NO;
			_lable_point4.hidden=NO;
			_lable_point5.hidden=YES;
			_lable_point6.hidden=YES;
		}
			break;
		case 5:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=NO;
			_lable_point3.hidden=NO;
			_lable_point4.hidden=NO;
			_lable_point5.hidden=NO;
			_lable_point6.hidden=YES;
		}
			break;
		case 6:{
			_lable_point.hidden=NO;
			_lable_point2.hidden=NO;
			_lable_point3.hidden=NO;
			_lable_point4.hidden=NO;
			_lable_point5.hidden=NO;
			_lable_point6.hidden=NO;
		}
			break;
		default:
			break;
	}
	if(_field.text.length>6){
		_field.text = [_field.text substringToIndex:6];
	}
}
- (void)btnClick:(UIButton *)btn {
	[self.passwordDelegate inputPasswordView:self withPasswordString:_TF.text WithButtonIndex:btn.tag];
	[self removeFromView];
}
- (void)hiddenAllPoint {
	_lable_point.hidden=YES;
	_lable_point2.hidden=YES;
	_lable_point3.hidden=YES;
	_lable_point4.hidden=YES;
	_lable_point5.hidden=YES;
	_lable_point6.hidden=YES;
}
- (void)removeFromView {
	[self removeFromSuperview];
}
- (void)dealloc {
	NSLog(@"dealloc");
}
-(UIView*)setupViewAddView:(UIView*)bg{
	UIView* view_box = [[UIView alloc]init];
	[view_box.layer setBorderWidth:0.5];
	view_box.layer.borderColor = [HLLineColor CGColor];
	view_box.layer.cornerRadius=3;
	view_box.layer.masksToBounds=YES;
	view_box.php_w=boxWidth;
	view_box.php_h=boxWidth;
	CGFloat Y=CGRectGetMaxY(_lable_title.frame)+20;
	view_box.php_y=Y;
	[bg addSubview:view_box];
	return view_box;
}
-(UILabel*)setupLabelAddView:(UIView*)bg{
	UILabel  *lable_point = [[UILabel alloc]init];
	lable_point.frame = CGRectMake((bg.frame.size.width-10)/2, (bg.frame.size.width-10)/2, 10, 10);
	[lable_point.layer setCornerRadius:5];
	[lable_point.layer setMasksToBounds:YES];
	lable_point.backgroundColor = [UIColor blackColor];
	[bg addSubview:lable_point];
	lable_point.hidden=YES;
	return lable_point;
}
@end
